use std::{
    sync::{Arc, Mutex},
    thread,
};

fn main() {
    let vec = Arc::new(Mutex::new(vec![]));
    let mut childs = vec![];

    for i in 0..5 {
        let v = vec.clone();
        let t = thread::spawn(move || {
            let mut v = v.lock().unwrap();
            v.push(i);
        });

        childs.push(t);
    }

    for t in childs {
        t.join().unwrap();
    }

    println!("{:?}", vec);
}
